package org.dcits.dao;

import java.util.List;
import java.util.Map;

import org.dcits.util.Jdbc;
import org.springframework.stereotype.Repository;

/**
 * 交易流水查询dao处理
 * 
 * @author czl
 *
 */
@Repository
public class TransHistoryDao {

	public boolean isExistClientNo(String acctNo) throws Exception {
		if (Jdbc.query("select user_id,acct_no from dcits.useracct where acct_no=?;", acctNo).size() != 0) {
			return true;
		} else {
			return false;
		}
	}

	public List<Map<String, Object>> queryTranHistory(String clientNo,String statu) throws Exception {
		List<Map<String, Object>> query=null;
		if ("0".equals(statu)) {
			query = Jdbc.query(
					"select a_acct_no,b_acct_no,salary,date,result,user_id from tranflow t,useracct u where t.a_acct_no=? and t.a_acct_no=u.acct_no || t.b_acct_no=? and t.b_acct_no=u.acct_no;",
					clientNo, clientNo);
		} else if ("1".equals(statu)) {// 转出
			query = Jdbc.query(
					"select a_acct_no,b_acct_no,salary,date,result,user_id from tranflow t,useracct u where t.a_acct_no=? and t.a_acct_no=u.acct_no",
					clientNo);
		} else if ("2".equals(statu)) {// 转入
			query = Jdbc.query(
					"select a_acct_no,b_acct_no,salary,date,result,user_id from tranflow t,useracct u where t.b_acct_no=? and t.b_acct_no=u.acct_no;",
					clientNo);
		}
		return query;
	}

	public List<Map<String, Object>> findAccNoByUserId(int userId) throws Exception {
		return Jdbc.query("select useracct.acct_no from useracct where useracct.user_id=?;",userId);
	}

}
